//1. 安装   npm  i redux
//2. 创建文件 src/redux/store.js
//3. 文件中编写功能
import {applyMiddleware, createStore} from 'redux'

//4. 创建仓库对象   @@init
const store = createStore((state=0, action) => {
  switch(action.type){
    case 'add':
      return;
    case 'minus':
      return;
    default:
      //一定不要忘了写 default 代码块
      return state;
  }
}, applyMiddleware(thunk));

// store.dispatch({type: 'add', payload: 10});

//封装 action creator(创造者)
export function jiaAction(data){
  return {type: 'add', payload: data}
}

export default store;

//异步更新状态
store.dispatch(dispatch => {
  setTimeout(() => {
    dispatch(jiaAction());
  }, 1000)
})

export function asyncIncreAction(){
  return dispatch => {
    setTimeout(() => {
      dispatch(jiaAction());
    }, 1000)
  }
}



